package com.syn.synold4s.control.dialog;

import static com.gaoyi.basemodule.baseUtil.DateFormatUtil.DateTimeToStr;
import static com.gaoyi.basemodule.baseUtil.OKHttpUtil.AI_SITE_IMG_URL;
import static com.gaoyi.basemodule.baseUtil.OKHttpUtil.BASE_NET_URL;

import android.content.Context;
import android.util.Log;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.gaoyi.basemodule.baseUtil.ImageUtil;
import com.gaoyi.basemodule.baseUtil.OKHttpUtil;
import com.gaoyi.basemodule.baseUtil.SPUtil;
import com.gaoyi.basemodule.baseconstant.SPName;
import com.gaoyi.basemodule.basedialog.BaseFragmentDialog;
import com.syn.synold4s.R;
import com.syn.synold4s.adapter.AlertAdapter;
import com.syn.synold4s.bean.dto.MapAllDeviceDto;
import com.syn.synold4s.databinding.TowerDialogBinding;

import java.text.SimpleDateFormat;

public class GoogleMapTowerDialog extends BaseFragmentDialog<TowerDialogBinding> {

    private MapAllDeviceDto data;
    private AlertAdapter alertAdapter;

    public GoogleMapTowerDialog(Context context, MapAllDeviceDto data) {
        super(context);
        this.data = data;
    }

    @Override
    protected void initView() {
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        mBinding.ivClose.setOnClickListener(view -> dismiss());
        setData();
    }

    private void setData() {
        if (data == null) return;
        alertAdapter = new AlertAdapter(mContext);
        mBinding.rv.setLayoutManager(new LinearLayoutManager(mContext));
        mBinding.rv.setAdapter(alertAdapter);
        mBinding.rv.setItemAnimator(null);
        if (data.getAlerts() != null && data.getAlerts().size() > 0) {
            mBinding.newDynamicLayout.setVisibility(View.VISIBLE);
            alertAdapter.submitList(data.getAlerts());
        }
        String aiSiteImgUrl = SPUtil.getInstance().getString(SPName.API_URL, BASE_NET_URL) + AI_SITE_IMG_URL;
        ImageUtil.loadImg(mBinding.ivPhoto, aiSiteImgUrl + "400/" + data.getPhoto(), R.drawable.error_img);
        mBinding.tvCraneName.setText(getString(R.string.tower_name) + data.getName());
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
//        if (data.getLastTime() != null) {
//            String time = simpleDateFormat.format(data.getLastTime());
//            mBinding.tvAlertTime.setText(getString(R.string.alert_time)+time);
//        }
        String time = DateTimeToStr(data.getLastTime(), "dd-MM-yyyy HH:mm:ss");
        mBinding.tvAlertTime.setText(getString(R.string.alert_time) + time);
        mBinding.tvAddress.setText(getString(R.string.address_) + data.getAddress());
    }

    @Override
    protected TowerDialogBinding getViewBinding() {
        return TowerDialogBinding.inflate(getLayoutInflater());
    }

    @Override
    protected String getShowTag() {
        return BOTTOM;
    }
}
